package eden.api.common.enums;

import lombok.Getter;

import java.math.BigDecimal;

/**
 * 产品分润模式
 */
@Getter
public enum CalTypeEnum {

    /**
     * 按照百分比
     */
    PERCENT_TYPE("按照百分比计算") {
        @Override
        public BigDecimal calAmount(BigDecimal amount, BigDecimal arg) {
            return amount.multiply(arg);
        }
    },
    /**
     * 按照固定金额
     */
    FIX_TYPE("按照固定值结算") {
        @Override
        public BigDecimal calAmount(BigDecimal amount, BigDecimal arg) {
            return arg;
        }
    };
    private final String description;
    public abstract BigDecimal calAmount(BigDecimal amount,BigDecimal arg);

    CalTypeEnum(String description) {
        this.description = description;
    }

    public static CalTypeEnum getCalTypeEnum(String name) {
        for (CalTypeEnum calTypeEnum : CalTypeEnum.values()) {
            if (calTypeEnum.name().equals(name)) {
                return calTypeEnum;
            }
        }
        return null;
    }
}
